#!/bin/zsh
####################
#                  #
#   ZOOMER SHELL   #
#                  #
####################

[ -f "$HOME/.cache/wal/colors.sh" ] && source "$HOME/.cache/wal/colors.sh" || wal -s -t -e --theme BubblePop.json
[ -f "$HOME/.config/shell/alias.sh" ] && source "$HOME/.config/shell/alias.sh"

# Enable colors
autoload -U colors && colors

#
# ZSH prompt
if [ "$(hostname)" = "framework" ]; then
    PROMPT="%n%F{${color1}}%f%m %F{${color1}}%f%~
%F{${color1}}%F{${foreground}} "
    RPROMPT=""
else
    PROMPT="%n%F{${color1}}%f%m %F{${color1}}%f%~ 
%F{${color1}}%F{${foreground}} "
    RPROMPT=""
fi

# Move history file
HISTSIZE=100
SAVEHIST=100
HISTFILE=~/.cache/zsh_history

# Basic auto/tab complete:
autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit -D
_comp_options+=(globdots)		# Include hidden files.

# Use vim keys in tab complete menu:
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history

# vi mode
bindkey -v
export KEYTIMEOUT=1
# Change cursor shape for different vi modes.
function zle-keymap-select {
  if [[ ${KEYMAP} == vicmd ]] ||
     [[ $1 = 'block' ]]; then
    echo -ne '\e[1 q'
  elif [[ ${KEYMAP} == main ]] ||
       [[ ${KEYMAP} == viins ]] ||
       [[ ${KEYMAP} = '' ]] ||
       [[ $1 = 'beam' ]]; then
    echo -ne '\e[5 q'
  fi
}
zle -N zle-keymap-select

echo -ne '\e[5 q' # Use beam shape cursor on startup.
preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.

# Plugins, load last
[ -f "$HOME/.config/shell/plugins.zsh" ] && source "$HOME/.config/shell/plugins.zsh"
